package com.itbaima.service.impl;

import com.itbaima.pojo.VO.SalaryVO;
import com.itbaima.mapper.SalaryMapper;
import com.itbaima.service.SalaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SalaryServiceImpl implements SalaryService {

    @Autowired
    private SalaryMapper salaryMapper;

    @Override
    public List<SalaryVO> getAllSalaries() {
        // 打印日志查看是否有查询数据
        List<SalaryVO> salaryList = salaryMapper.findAllSalaries();
        System.out.println("查询到的薪资数据：" + salaryList);  // 调试输出
        return salaryList;
    }




    @Override
    public boolean updateSalary(Integer salaryId, Double bonus, Double dock) {
        int result = salaryMapper.updateSalary(salaryId, bonus, dock);
        return result > 0;  // 如果更新成功，返回true
    }
    @Override
    public boolean updateBonusAndDock(SalaryVO salaryVO) {
        // 从 VO 中提取 salaryId、bonus 和 dock
        Integer salaryId = salaryVO.getSalary_id();
        Double bonus = salaryVO.getBonus();
        Double dock = salaryVO.getDock();

        // 更新奖励金和扣除金
        int result = salaryMapper.updateSalary(salaryId, bonus, dock);
        return result > 0;  // 返回是否更新成功
    }
}

